export interface IHandle {
	destroy(this: IHandle): void;
}

export interface IFeidaoAi {
	readonly data: {
		readonly [attr: string]: any;
	};
	fire(action: string, ...args: any[]): Promise<any>;
	emit(event: string, ...args: any[]): Promise<any>;
}

export interface IFeidaoAiBrowserComponent extends IFeidaoAi {
	readonly data: {
		readonly [attr: string]: any;
		readonly no: string;
		readonly node: HTMLElement;
		readonly params: { [key: string]: any; };
		readonly url: string;
	};
	parse_event(node: HTMLElement | DocumentFragment): IHandle[];
}

export interface IFeidaoAiWeappAppData {
	readonly [attr: string]: any;
	readonly app: wx.App;
	inner_audio_context?: wx.InnerAudioContext;
	background_audio_manager?: wx.BackgroundAudioManager;
	record_manager?: wx.RecorderManager;
	video_context?: wx.VideoContext;
	camera_context?: wx.CameraContext;
}

export interface IFeidaoAiWeappPage extends IFeidaoAi {
	readonly data: {
		readonly [attr: string]: any;
		readonly spaceid: string;
		readonly page: wx.Page;
		readonly params: { [name: string]: string; };
		readonly fd: IFeidaoAiWeappAppData;
	};
}

export interface IFeidaoAiBrowserPage extends IFeidaoAi {
	readonly data: {
		readonly [attr: string]: any;
		readonly params: { [key: string]: any; };
		readonly url: string;
	};
}

export interface IParam {
	'$or'?: string[];
	'$nor'?: string[];
	[key: string]: string | number | boolean | any;
}

export interface IPaging {
	size: number;
	index: number;
}

export interface ISort {
	[field: string]: 0 | 1;	// ? -1 for desc
}

export interface ICondition {
	param?: IParam;
	paging?: IPaging;
	sort?: ISort;
}

export interface ICommonParams {
	body?: any;
	cookie: {
		[name: string]: string;
	};
	data: any;
	headers: {
		[key: string]: string;
	};
	params: any;
	query: any;
	remote_address: string;
	spaceid: string;
	url: string;
	[key: string]: any;
}

export interface IHeaders {
	actionid: string;
	messagetype: string;
	sessionid: string;
	spaceid: string;
}

import { HTMLElement as NodeHTMLElement } from 'node-html-parser';

export interface IFeidaoAiNodejsComponent extends IFeidaoAi {
	readonly data: {
		readonly [attr: string]: any;
		readonly msg: ICommonParams;
		readonly headers: IHeaders;
		readonly actionid: string;
		readonly sessionid: string;
		readonly spaceid: string,
		readonly no: string;
		readonly node: NodeHTMLElement;
		readonly params: { [key: string]: any; };
		readonly url: string;
	};
}

export interface IFeidaoAiNodejsPage extends IFeidaoAi {
	readonly data: {
		readonly [attr: string]: any;
		readonly msg: ICommonParams;
		readonly headers: IHeaders;
		readonly actionid: string;
		readonly sessionid: string;
		readonly spaceid: string,
		readonly params: { [key: string]: any; };
		readonly url: string;
	};
}

export interface IWebResult {
	data?: any;
	buff?: Buffer;
	cookie?: {
		[name: string]: string;
	};
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export interface IDesktopSendMsg {
	reply: string;
	spaceid: string;
	type: string;
	msg: any;
	timeout: number;
}

export interface IFeidaoAiDesktopApp extends IFeidaoAi {
	readonly data: {
		readonly spaceid: string;
		// mainWindow: BrowserWindow;
	};
}

export interface IFeidaoAiWeappApp extends IFeidaoAi {
	readonly data: IFeidaoAiWeappAppData;
}

export interface IFeidaoAiAliappAppData {
	readonly [attr: string]: any;
	readonly app: my.App;
}

export interface IFeidaoAiAliappPage extends IFeidaoAi {
	readonly data: {
		readonly [attr: string]: any;
		readonly spaceid: string;
		readonly page: my.Page;
		readonly params: {
			[name: string]: string;
		};
		readonly fd: IFeidaoAiAliappAppData;
	};
}
